package 天津大学;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

public class TJu {
    public static void main(String[] args) throws IOException {
        for (int i = 1; i <= 24; i++) {
            String PageUrl = "http://faculty-cn.tju.edu.cn/xyjslb.jsp" + "?totalpage=24&PAGENUM=" + i + "&id=1012&urltype=tsites.CollegeTeacherList&wbtreeid=1021&st=0&lang=zh_CN";
//            boolean equals = PageUrl.equals("http://faculty-cn.tju.edu.cn/xyjslb.jsp?totalpage=24&PAGENUM=2&id=1012&urltype=tsites.CollegeTeacherList&wbtreeid=1021&st=0&lang=zh_CN");
            Document parse = Jsoup.connect(PageUrl).post();
            Elements elementsByClass = parse.getElementsByClass("b-search");
            for (Element byClass : elementsByClass) {
                Elements li = byClass.getElementsByTag("li");
                for (Element element : li) {
                    String attr = element.getElementsByTag("a").attr("href");
                    Document post = Jsoup.connect(attr).post();
                    for (Element teacherTitle : post.getElementsByClass("teacherTitle")) {
                        System.out.println(teacherTitle.text());
//                        for (Element element1 : teacherTitle.getElementsByTag("li")) {
//                            Elements li1 = element1.getElementsByTag("li");
//                            String span = li1.get(0).getElementsByTag("span").get(1).text();
//                            System.out.println(span);
//                        }


//                        for (Element contact : post.getElementsByClass("contact")) {
//                            Elements li1 = contact.getElementsByTag("li");
//                            for (Element element1 : li1) {
//                                String text = element1.text();
//                                System.out.println(text);
//                            }
//                        }
                        System.out.println("+++++++++++++++++++++++");
                    }
                }
            }
        }

    }
}
